package top.canyue.word_range.handler;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.canyue.word_range.result.Result;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * SQL异常捕获
 */
@RestControllerAdvice
public class SQLExceptionHandler {

    @ExceptionHandler(SQLException.class)
    public Result<Object> handleSQLException(SQLException e) {
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public Result<Object> handleSQLIntegrityConstraintViolationException(SQLIntegrityConstraintViolationException e) {
        return Result.error("SQL约束异常");
    }

}
